package com.pingsky.apm.agent.core.trace;


import com.pingsky.apm.agent.core.AgentId;
import com.pingsky.apm.agent.core.util.StringUtil;

import java.util.concurrent.atomic.AtomicLong;

public final class TraceIdGenerator {

    private final static String APPLICATION_NAME = AgentId.INSTANCE.getApplicationName();

    private final static AtomicLong TRACE_ID_SEQUENCE = new AtomicLong(1L);

    private TraceIdGenerator() {
    }

    public static String generate() {
        return StringUtil.join(
                '.',
                APPLICATION_NAME,
                String.valueOf(Thread.currentThread().getId()),
                String.valueOf(TRACE_ID_SEQUENCE.getAndIncrement())
        );
    }
}
